/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rultax.blackice.physics.panel;

import com.rultax.blackice.physics.VectorConverter;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Float;
import javax.swing.JPanel;
import org.jbox2d.common.Vec2;

/**
 *
 * @author scottw
 */
public class PanelVectorConverter implements VectorConverter<Vec2, Point2D.Float> {

    private JPanel screen;
    private float transX;
    private float transY;
    private float scaleFactor;
    private float yFlip;

    public PanelVectorConverter(JPanel screen, float transX, float transY, float scaleFactor) {
	this.screen = screen;
	this.transX = transX;
	this.transY = transY;
	this.scaleFactor = scaleFactor;
	yFlip = -1;
    }    
    
    @Override
    public Vec2 screenToWorld(Float vec) {
	Vec2 u = new Vec2(vec.x / scaleFactor, vec.y / scaleFactor);
	u.y *= yFlip;
	return u;
    }

    @Override
    public Float worldToScreen(Vec2 vec) {
	Point2D.Float u = new Float(vec.x * scaleFactor, vec.y * scaleFactor);
	u.y *= yFlip;
	return u;
    }
}
